package com.zxl.soft.generator.test.controller;

import com.zxl.soft.generator.test.entity.ChineseWord;
import com.zxl.soft.generator.test.service.ChineseWordService;
import com.zxl.soft.generator.test.param.ChineseWordQueryParam;
import com.zxl.soft.generator.test.param.ChineseWordQueryNonePageParam;
import com.zxl.soft.generator.test.vo.ChineseWordQueryVo;
import com.zxl.soft.generator.common.api.ApiResult;
import com.zxl.soft.generator.common.controller.BaseController;
import com.zxl.soft.generator.common.vo.Paging;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import org.springframework.beans.BeanUtils;

import javax.validation.Valid;

/**
 * <pre>
 *  前端控制器
 * </pre>
 *
 * @author zhaoxl
 * @since 2021-08-12
 */
@Slf4j
@RestController
@RequestMapping("/chineseWord")
@Api(" API")
public class ChineseWordController extends BaseController {

    @Autowired
    private ChineseWordService chineseWordService;

    /**
     * 添加
     */
    @PostMapping("/add")
    @ApiOperation(value = "添加ChineseWord对象", notes = "添加", response = ApiResult.class)
    public ApiResult<Boolean> addChineseWord(@Valid @RequestBody ChineseWordQueryVo chineseWordQueryVo) throws Exception {
        ChineseWord chineseWord = new ChineseWord();
        BeanUtils.copyProperties(chineseWordQueryVo,chineseWord);

        boolean flag = chineseWordService.saveChineseWord(chineseWord);
        return ApiResult.result(flag);
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    @ApiOperation(value = "修改ChineseWord对象", notes = "修改", response = ApiResult.class)
    public ApiResult<Boolean> updateChineseWord(@Valid @RequestBody ChineseWordQueryVo chineseWordQueryVo) throws Exception {
        ChineseWord chineseWord = new ChineseWord();
        BeanUtils.copyProperties(chineseWordQueryVo,chineseWord);
        boolean flag = chineseWordService.updateChineseWord(chineseWord);
        return ApiResult.result(flag);
    }

    /**
     * 删除
     */
    @PostMapping("/delete/{id}")
    @ApiOperation(value = "删除ChineseWord对象", notes = "删除", response = ApiResult.class)
    public ApiResult<Boolean> deleteChineseWord(@PathVariable("id") Long id) throws Exception {
        boolean flag = chineseWordService.deleteChineseWord(id);
        return ApiResult.result(flag);
    }

    /**
     * 获取
     */
    @GetMapping("/info/{id}")
    @ApiOperation(value = "获取ChineseWord对象详情", notes = "查看", response = ChineseWordQueryVo.class)
    public ApiResult<ChineseWordQueryVo> getChineseWord(@PathVariable("id") Long id) throws Exception {
        ChineseWordQueryVo chineseWordQueryVo = chineseWordService.getChineseWordById(id);
        return ApiResult.ok(chineseWordQueryVo);
    }

    /**
     * 分页列表
     */
    @PostMapping("/getPageList")
    @ApiOperation(value = "获取ChineseWord分页列表", notes = "分页列表", response = ChineseWordQueryVo.class)
    public ApiResult<Paging<ChineseWordQueryVo>> getChineseWordPageList(@Valid @RequestBody ChineseWordQueryParam chineseWordQueryParam) throws Exception {
        Paging<ChineseWordQueryVo> paging = chineseWordService.getChineseWordPageList(chineseWordQueryParam);
        return ApiResult.ok(paging);
    }

    /**
    * 对象列表
    */
    @PostMapping("/getList")
    @ApiOperation(value = "获取ChineseWord集合列表", notes = "分页列表", response = ChineseWordQueryVo.class)
    public ApiResult<List<ChineseWordQueryVo>> getChineseWordList(@Valid @RequestBody ChineseWordQueryNonePageParam chineseWordQueryNonePageParam) throws Exception {
    List<ChineseWordQueryVo> chineseWordList = chineseWordService.getChineseWordList(chineseWordQueryNonePageParam);
    return ApiResult.ok(chineseWordList);
}

}

